home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 26 / AACD 26.iso / AACD / Online / x3270 / unix_files / Examples / child_script.ksh < prev    next >
Encoding:
Text File  |  2005-09-29  |  2.2 KB  |  117 lines

  1. #! /bin/ksh
  2. # TSO login script, to be run via the x3270 Script() action.
  3. # ksh version
  4.  
  5. set -x
  6. me=${0##*/}
  7.  
  8. # Make sure we're in the right environment.
  9. if [ -z "$X3270INPUT" -o -z "$X3270OUTPUT" ]
  10. then    print -u2 "$me: must be run via the x3270 Script() action."
  11.     exit 1
  12. fi
  13.  
  14. # Set up login parameters
  15. tcp_host=${1-ibmsys}
  16. dial_user=${2-VTAM}
  17. sna_host=${3-TSO}
  18. userid=${4-USERID}
  19. password=${5-PASSWORD}
  20.  
  21. # Verbose flag for x3270if
  22. v="-v"
  23.  
  24. # Define some handly local functions.
  25.  
  26. # Common x3270 Ascii function
  27. function ascii
  28. {
  29.     x3270if $v 'Ascii('$1')'
  30. }
  31.  
  32. # Common x3270 String function
  33. function string
  34. {
  35.     x3270if $v 'String("'"$@"'")'
  36. }
  37.  
  38. # x3270 cursor column
  39. function cursor_col
  40. {
  41.     x3270if $v -s 10
  42. }
  43.  
  44. # x3270 connection status
  45. function cstatus
  46. {
  47.     x3270if $v -s 4
  48. }
  49.  
  50. # Failure.
  51. function die
  52. {
  53.     x3270if $v "Info(\"$me error: $@\")"
  54.     x3270if $v "CloseScript(1)"
  55.     exit 1
  56. }
  57.  
  58. # Make sure we're connected.
  59. x3270if $v Wait
  60. [ "$(cstatus)" = N ] && die "Not connected."
  61.  
  62. # Get to a VM command screen
  63. x3270if $v Enter
  64.  
  65. # Wait for VM's prompt
  66. while [ "$(ascii 1,0,5)" != "Enter" ]
  67. do    sleep 2
  68. done
  69.  
  70. # Dial out to VTAM
  71. string "DIAL $dial_user"
  72. x3270if $v Enter
  73. typeset -i sl=10+${#dial_user}
  74. typeset -i dl=5+${#dial_user}
  75. while [ "$(ascii 0,64,4)" != VTAM ]
  76. do    s="$(ascii 8,0,$sl | sed 's/^ *//')"
  77.     if [ "$s" != "DIALED TO $dial_user" -a "$s" != "" ]
  78.     then    if [ "$(ascii 7,0,$dl)" = "DIAL $dial_user" ]
  79.         then    die "Couldn't get to VTAM"
  80.         fi
  81.     fi
  82.     sleep 2
  83. done
  84.  
  85. # Get to the SNA host
  86. string "$sna_host $userid"
  87. x3270if $v Enter
  88.  
  89. # Pass VTAM digestion message and initial blank TSO screen
  90. while [ "$(ascii 0,21,20)" = "USS COMMAND HAS BEEN" ]
  91. do    sleep 2
  92. done
  93. while :
  94. do    s="$(ascii 0,33,11 | sed 's/^ *//')"
  95.     [ "$s" != "" ] && break
  96.     sleep 2
  97. done
  98.  
  99. # Now verify the "TSO/E LOGON" screen
  100. [ "$s" = "TSO/E LOGON" ] || die "Couldn't get to TSO logon screen"
  101.  
  102. # Pump in the password
  103. string "$password"
  104. x3270if $v Enter
  105.  
  106. # Now look for "LOGON IN PROGRESS"
  107. typeset -i nl=18+${#userid}
  108. [ "$(ascii 0,11,$nl)" = "$userid LOGON IN PROGRESS" ] || die "Couldn't log on"
  109.  
  110. # Make sure TSO is waiting for a '***' enter
  111. [ "$(cursor_col)" -eq 5 ] || die "Don't understand logon screen"
  112.  
  113. # Off to ISPF
  114. x3270if $v Enter
  115.  
  116. # No need to explicitly call CloseScript -- x3270 will interpret EOF as success.
  117.